package cn.itlaobing.eshop.web.servlet;/**
 * Created by 1223 on 2017/11/14.
 */

import cn.itlaobing.eshop.dao.FocussDao;
import cn.itlaobing.eshop.dao.GoodsDao;
import cn.itlaobing.eshop.entity.GoodsDTO;
import cn.itlaobing.eshop.entity.ItlbFocuss;
import cn.itlaobing.eshop.web.annotation.RequestMapping;
import org.apache.log4j.Logger;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

/**
 * 类名：
 * 描述：
 * 作者：陈志凯
 * 时间：2017/11/14
 */
@WebServlet("/goods/*")
public class GoodsServlet extends BaseServlet{
    Logger logger=Logger.getLogger(GoodsServlet.class);
    @RequestMapping("/show")
    public void show(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        GoodsDao goodsDao=new GoodsDao();
        try {
            //热销
            List<GoodsDTO> list=goodsDao.queryHotSale();
            logger.info(list);
            request.setAttribute("goods",list);

            //最新上架
            List<GoodsDTO> listNew=goodsDao.queryNewSale();
            logger.info(listNew);
            request.setAttribute("newGoods",listNew);

            //焦点图
            FocussDao focussDao=new FocussDao();
            List<ItlbFocuss> listFocuss=focussDao.queryFoucss();
            logger.info(listFocuss);
            request.setAttribute("listFocuss",listFocuss);

        } catch (SQLException e) {
            e.printStackTrace();
        }

        request.getRequestDispatcher("/WEB-INF/views/index.jsp").forward(request,response);
        return ;

    }
    @RequestMapping("/detail")
    public void detail(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
        GoodsDao goodsDao=new GoodsDao();
        GoodsDTO goodsDTO=new GoodsDTO();
        String strid=request.getParameter("id");
        Long id=Long.valueOf(strid);
        try {
            goodsDTO=goodsDao.queryById(id);
            request.setAttribute("details",goodsDTO);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        request.getRequestDispatcher("/WEB-INF/views/detail.jsp").forward(request,response);
        return;
    }


}
